home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 July / Ahoy_Magazine_87-07_1987_Double_L_Side_A.d64 / LED Driver (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  2KB  |  69 lines

  1. 0 rem << rr43-1 >>
  2. 1 rem===================================
  3. 2 print"[147]         led driver"
  4. 3 rem        rupert report #43
  5. 4 rem  use cassette port motor output
  6. 5 rem          to light led
  7. 6 rem===================================
  8. 10 rem ====== initialization ==========
  9. 20 def fns(b)=peek(m) or 2^b       :rem  set bit b of location m
  10. 30 def fnc(b)=peek(m) and not 2^b  :rem  clear bit b of location m
  11. 40 m=0 : poke m,fns(4) :rem set ddr for  bit 4 to be output
  12. 50 m=1 : poke m,fnc(4) :rem clear bit 4  of $1 so $192 is not cleared by irq
  13. 60 poke 192,1          :rem set $192 so  irq does not turn motor on
  14. 70 pk=peek(1) : l1=pk and not 32 : l0=pk or 32  :rem  on and off poke values
  15. 80 df=.50    :rem duty factor = 50%
  16. 90 k=2.5 : p=10^k : w1=df*p : w0=p-w1    :rem initial period and pulse widths
  17. 95 print "[147]" : gosub 2000 :rem graph
  18. 100 rem ====== main loop ===============
  19. 110 if df=0 then 130
  20. 120 poke 1,l1 : for n=1 to w1: next
  21. 130 get a$ : if a$<>"" then gosub 1000
  22. 140 if df=1 then 120
  23. 150 poke 1,l0 : for n=1 to w0 : next
  24. 160 get a$ : if a$<>"" then gosub 1000
  25. 170 goto 110
  26. 1000 rem ====== keyboard input =========
  27. 1010 rem  +  increases frequency
  28. 1020 rem  -  decreases frequency
  29. 1030 rem 1-9 = duty factor (10 to 90%)
  30. 1040 rem 0 = toggle duty factor (0/100%)
  31. 1050 rem
  32. 1060 if val(a$)>0 then df=0.1*val(a$) :  rem  1 to 9 selected
  33. 1070 if a$="0" then df=-1*(df=0) :  rem  toggle 0 or 1
  34. 1080 if a$="-" then k=k+.5 :if k>3.5 then k=3.5  : rem increase period
  35. 1090 if a$="+" then k=k-.5 :if k<.5 then k=.5 :rem decrease period/increase freq
  36. 1100 p=10^k            :rem get period
  37. 1110 w1=df*p : w0=p-w1 :rem pulse widths
  38. 1120 get a$ : if a$<>"" then 1060 : rem  any more keys?
  39. 1130 gosub 2000  :rem  display bar graph
  40. 1140 return
  41. 2000 rem ======= bargraphs =============
  42. 2010 print""; : for n=1 to 33 : print"[190]"; : next : print
  43. 2020 print"duty factor: "; : gosub 2100
  44. 2025 if df=0 then print"0";  : goto 2040
  45. 2030 for n=1 to df*10+.1 : print "[184][184]"; : next
  46. 2040 print : print"frequency  : "; : gosub 2100
  47. 2050 for n=1 to 10-3*(k-.5)
  48. 2060 print"[185][185]"; : next
  49. 2070 return
  50. 2100 for n=1 to 20 : print" "; : next
  51. 2110 for n=1 to 20 : print"[157]"; : next
  52. 2120 return
  53. 2990 rem ====== duty factor demo =======
  54. 2991 rem > add line 99 goto 3000
  55. 2992 rem > rapidly move the led
  56. 2993 rem   back and forth.
  57. 2994 rem > look at the relative widths
  58. 2995 rem   of light and dark streaks
  59. 2996 rem   as the duty factor changes.
  60. 2997 rem ===============================
  61. 3000 p0=9 : p1=1 : gosub 3050
  62. 3010 p0=5 : p1=5 : gosub 3050
  63. 3020 p0=1 : p1=9 : gosub 3050
  64. 3030 goto 3000
  65. 3050 for ct=1 to 50
  66. 3060 poke 1,l0 : for n=1 to p0 : next
  67. 3070 poke 1,l1 : for n=1 to p1 : next
  68. 3080 next : return
  69.